package com.gilight.base.controller;

import com.gilight.base.base.ResultEntity;
import com.gilight.base.model.SysUser;
import com.gilight.base.service.MenuService;
import com.gilight.base.util.ShiroUtil;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.collections4.MapUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/web/menu")
public class MenuController {

    @Autowired
    private MenuService menuServiceImpl;

    @RequestMapping(value = "/loadMenu", method = {RequestMethod.POST, RequestMethod.GET})
    public ResultEntity loadMenu(@RequestBody Map <String,Object> map) {
        String appKey = MapUtils.getString(map,"appKey",null);
        ResultEntity resultEntity = new ResultEntity();
        List<Map<String,Object>>list = menuServiceImpl.loadMenu2(appKey);
        resultEntity.setData(list);
        return resultEntity;
    }

    /**
     * 切换角色接口
     * @param roleId
     * @return
     */
    @ApiOperation("切换角色查询菜单接口")
    @RequestMapping(value = "/changeMenu", method = {RequestMethod.POST, RequestMethod.GET})
    public ResultEntity saveChangeMenu(Long roleId) {
        ResultEntity resultEntity = new ResultEntity();
        SysUser sysUser = ShiroUtil.getUser();
        menuServiceImpl.saveChangeMenu(sysUser.getId(),roleId);
        resultEntity.setData(true);
        return resultEntity;
    }
}
